package homework07;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class homework003 {
	public static void main(String[] args) throws IOException {
		File file=new File("D:\\homework");
		File file1=new File("D:\\workhome");
		copyFile(file,file1);
	}
	public static void copyFile(File file,File dest) throws IOException{
		dest.mkdirs();
		File[] files=file.listFiles();
		for (File f:files){
			if (f.isFile()){
				FileInputStream fis=new FileInputStream(f);
				FileOutputStream fos=new FileOutputStream(new File(dest,f.getName()));
				byte[] bytes=new byte[1024*1024];
				int len;
				while((len=fis.read(bytes))!=-1){
					fos.write(bytes,0,len);
				}
				//fos.close();
				//fis.close();
			}else{
				copyFile(f,new File(dest,f.getName()));
			}
		}
	}
}
